<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>39-折叠菜单</title>
    <style>
        *{
             margin: 0;
             padding: 0;
        }
        .nav{
            list-style: none;
            width: 300px;
            height: 100px;
            margin: 100px auto;
        }
        .nav>li{
            border: 1px solid #000000;
            line-height: 35px;
            border-bottom: none;
            text-indent: 2em;
            position: relative;
        }
        .nav>li:last-child{
            border-bottom: 1px solid #000000;
            border-bottom-right-radius: 10px;
            border-bottom-left-radius: 10px;
        }
        .nav>li:first-child{
            border-top-right-radius: 10px;
            border-top-left-radius: 10px;
        }
        .nav>li>span{
            background: url("images/arrow_right.png") no-repeat center center;
            width: 32px;
            height: 32px;
            display: inline-block;
            position: absolute;
            right: 10px;
            top: 5px;
        }
        .sub{
            display: none;
        }
        .sub>li{
            list-style: none;
            background: #779dbd;
            border-bottom:1px solid #cccccc;
        }
        .sub>li:hover{
            background: #FF0000;
        }
        .nav>.current>span{
            transform: rotate(90deg);
        }

    </style>
    <script src="jQuery/jquery-3.4.1.js"></script>
    <script>
         $(function () {
                $(".nav>li").click(function () {
                    var $sub=$(this).children(".sub");
                    $sub.slideToggle(800);
                    var otherSub=$(this).siblings().children(".sub");
                    otherSub.slideUp(800);
                    $(this).addClass("current");
                    $(this).siblings().removeClass("current");
                })
         })
    </script>
</head>
<body>
<ul class="nav">
    <li>一级菜单<span></span>
        <ul class="sub">
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
        </ul>
    </li>
    <li>一级菜单<span></span>
        <ul class="sub">
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
        </ul>
    </li>
    <li>一级菜单<span></span>
        <ul class="sub">
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
        </ul>
    </li>
    <li>一级菜单<span></span>
        <ul class="sub">
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
        </ul>
    </li>
    <li>一级菜单<span></span>
        <ul class="sub">
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
        </ul>
    </li>
    <li>一级菜单<span></span>
        <ul class="sub">
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
        </ul>
    </li>
    <li>一级菜单<span></span>
        <ul class="sub">
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
            <li>二级菜单</li>
        </ul>
    </li>
    <li>一级菜单<span></span></li>
</ul>
</body>
</html>